import React from 'react';
import {View, Button, Alert} from 'react-native';
import ImageViewer from 'react-native-image-zoom-viewer';
import {CameraRoll} from '@react-native-camera-roll/camera-roll';

const images = [
  {
    url: 'https://res.vmallres.com/uomcdn/CN/cms/202408/5442d69d916d4bcf9ee740d595a164fb.jpg',
  },
  {
    url: 'https://res.vmallres.com/uomcdn/CN/cms/202502/b709d5e479b74bb5bf69c378716632a6.jpg',
  },
  {
    url: 'https://res.vmallres.com/uomcdn/CN/cms/202411/5e97b6d92252456289c17a82b609ec42.jpg',
  },
];

const menusImag = ({cancel, saveToLocal}: any) => {
  const save = () => {
    saveToLocal();
  };
  const onCancel = () => {
    cancel();
  };
  return (
    <View>
      <Button title="点击取消" onPress={onCancel}></Button>
      <Button title="点击保存" onPress={save}></Button>
    </View>
  );
};

const ImageView = () => {
  return (
    <View style={{flex: 1}}>
      <ImageViewer
        imageUrls={images}
        menus={menusImag}
        onSave={e => {
          CameraRoll.saveAsset(e)
            .then(res => {
              console.log('保存成功:', res);
            })
            .catch(err => {
              console.log('保存失败:', err);
            });
        }}
      />
    </View>
  );
};

export default ImageView;
